/* global JRoll, axios */

import html from './home.html'
import '../mycomponents/appbar.js'
import '../components/body.js'
import '../vendors/axios.min.js'
import '../vendors/jroll-vue-infinite.js'
import api from './interface/api.js'

export default {
  template: html,
  components: {
    'jroll-infinite': JRoll.VueInfinite({
      bottomed: function () {
        var parent = this.$parent
        var me = this
        if (this.page < (this.total || 1)) {
          axios.get(api.list + '?page=' + (this.page + 1)).then(function (res) {
            if (res.data.msg === 'success') {
              me.page++
              me.total = res.data.total
              parent.items = parent.items.concat(res.data.result)
              if (me.page === res.data.total) {
                me.tip = '没有更多数据啦！'
              }
            }
          })
        }
      }
    }, {
      scrollBarY: true
    })
  },
  data: function () {
    return {
      items: []
    }
  },
  methods: {
    gotoDetail: function (id) {
      this.go('pages/detail?id=' + id)
    }
  }
}
